/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exercises.day02.pt01;

import java.util.ArrayList;
import java.util.Collections;

/**
 *
 * @author (jaice)
 * @version 0.1 (may 28, 2012)
 * 
 * c. Design and implement a class called Card that represents a standard
 * playing card. Each card has a suit and a face value. Create a class called
 * DeckOfCards that stores 52 objects of the Card class. Include methods to shuffle
 * the deck, deal a card, and report the number of cards left in the deck. The shuffle 
 * method should assume a full deck. Create a test class with a main method that deals 
 * each card from a shuffled deck, printing each card as it is dealt.
 * 
 * 
 */
public class Deck {

    private Card card;
    private int cardsUsed;
    private ArrayList<String> list = new ArrayList();

    public Deck() {
        // Create an unshuffled deck of cards.

       

        for (int suit = 0; suit <= 3; suit++) {//loop card type

            for (int value = 1; value <= 13; value++) {//loop card value
                card = new Card(value, suit);
                //add card to list
                list.add(card.toString());
              
            }
        }
        cardsUsed = 0;
    }

    /*-----------------------------------------------------------------------------*/
    public void shuffleDeck() //swaping any 2 random card from the deck shuffles it
    {

        Collections.shuffle(list);

    }


    /*-----------------------------------------------------------------------------*/
    public int cardsLeft() {
        // Returns the number of cards that are still left in the deck.
        return 52 - cardsUsed;
    }

    /*-----------------------------------------------------------------------------*/
    public String dealCard() {
        // Deals one card from the deck and returns that card.
        if (cardsUsed == 52) {
            shuffleDeck();
        }
        
        cardsUsed++;
        //   return card[cardsUsed - 1].toString();
        return list.get(cardsUsed);
        
    }
}
